import os.path
import chardet

rootDir = '/Users/project/heavy-energy/front/s3-sany-heavy-energy/src/app' \
          '/pages/base-data/material-template/fan-check-template/fan-check-template-detail'


#
# old = "test-"
# new = "fan-check-"
# str/list

old = "Test"
new = "FanCheck"

for parent, dirnames, filenames in os.walk(rootDir):
    print(filenames)

    for filename in filenames:
        ps = parent+ "/"+ filename

        if ps.find(".DS_Store")!=-1:
            continue

        print(ps)
        with open(ps, 'r+', encoding = 'utf-8') as filetxt:
            while 1:
                ls=''
                line = filetxt.readline()
                if line=='':
                    break


                if line.find("../../") !=-1:
                    print(line)

                    line = line.replace("../../../", "../../../../")
                    print(line)
                    # lines = lines.replace(old, new)
                ls = ls+ line
            filetxt.seek(0)
            filetxt.write(ls)




